1 using UnityEngine;
2 using
System;
3 using
System.Collections;
4
5
6 public
class Vector3TweenProperty : AbstractVector3TweenProperty, IGenericProperty
7 {
8     
public string propertyName { get; private set; }
9     
private Action<Vector3> _setter;
10     
11     
12     
public Vector3TweenProperty( string propertyName, Vector3 endValue, bool isRelative = false ) : base( endValue, isRelative )
13     {
14         
this.propertyName = propertyName;
15     }

16     
17     
18     ///
<summary>
19     ///
validation checks to make sure the target has a valid property with an accessible setter
20     ///
</summary>
21     
public override bool validateTarget( object target )
22     {
23         
// cache the setter
24         _setter = GoTweenUtils.setterForProperty<Action<Vector3>>( target, propertyName );
25         
return _setter != null;
26     }
27
28     
29     
public override void prepareForUse()
30     {
31         
// retrieve the getter
32         
var getter = GoTweenUtils.getterForProperty<Func<Vector3>>( _ownerTween.target, propertyName );
33         
34         _endValue = _originalEndValue;
35         
36         
// if this is a from tween we need to swap the start and end values
37         
if( _ownerTween.isFrom )
38         {
39             _startValue = _endValue;
40             _endValue = getter();
41         }
42         
else
43         {
44             _startValue = getter();
45         }
46         
47         
base.prepareForUse();
48     }
49     
50     
51     
public override void tick( float totalElapsedTime )
52     {
53         
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
54         
var vec = GoTweenUtils.unclampedVector3Lerp( _startValue, _diffValue, easedTime );
55         
56         _setter( vec );
57     }
58
59 }



Trò chơi Angry Birds trong UNITY Engine 31.682 lượt xem

Gõ tìm kiếm nhanh...